import request from '@/utils/request'
import {func} from "@/uni_modules/uv-ui-tools/libs/function/test";

// 查询字典数据列表
export function getDict(type) {
  return request({
    url: '/system/dict-data/type?type='+type,
    method: 'get'
  })
}

// 翻译字典数据
export function returnDictLabel(val, dicList) {
  val = val + '';
  let arr = val.split(',');
  let labelList = [];
  for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < dicList.length; j++) {
      if (arr[i] == dicList[j].value) {
        labelList.push(dicList[j].label);
      }
    }
  }
  return labelList.join(',');
}

let dictList = [];
const returnDictTypeArrLabel = (val,type) => {
  let dictName = null;
  getDict(type).then(res => {
    dictList = res.data
    dictName = returnDictLabel(val, dictList);
    return dictName;
  });
}

export {
  returnDictTypeArrLabel
}

// 返回字典颜色
export function returnDictColor(val, dicList) {
	let colorStr =''
  for (let j = 0; j < dicList.length; j++) {
    if (val == dicList[j].value) {
  		colorStr = dicList[j].colorType
    }
  }
  return colorStr;
}
